package com.xuecheng.content.controller;

import com.xuecheng.api.content.model.CourseBaseAudiApi;
import com.xuecheng.api.content.model.dto.CourseBaseDTO;
import com.xuecheng.api.content.model.qo.QueryCourseModel;
import com.xuecheng.api.content.model.vo.CourseAuditVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.EntityMapper;
import com.xuecheng.content.service.CourseBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程基本信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CourseBaseAuditController implements CourseBaseAudiApi {

    @Autowired
    private CourseBaseService courseBaseService;

    public static final Long COMPANY = -1122334L;

    /**
     * 审核前必须提交
     * 修改为提交
     * @param courseId
     */
    @Override
    @GetMapping("course/commit/{courseId}")
    public void updateAuditStatus(@PathVariable Long courseId) {
        Long companyId = SecurityUtil.getCompanyId();

        courseBaseService.updateAuditStatus(courseId, companyId);
    }


    /**
     * 审核查询
     * @param params
     * @param model
     * @return
     */
    @Override
    @PostMapping("m/course/list")
    public PageVO queryCourseList(PageRequestParams params, @RequestBody QueryCourseModel model) {

        return courseBaseService.queryCourseList(params, model,COMPANY);
    }

    /**
     * 审核操作（拒绝or同意）
     * @param vo
     */
    @Override
    @PostMapping("m/courseReview/approve")
    public void selectOrUpdateAuditStatus(@RequestBody CourseAuditVO vo) {

        CourseBaseDTO courseBaseDTO = EntityMapper.INSTANCE.courseAuditVoToCourseBaseDTo(vo);

        courseBaseService.selectOrUpdateAuditStatus(courseBaseDTO);
    }


}
